home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-06-16 | 10.9 KB | 546 lines | [TEXT/MPS ] |
- CASE OBJECT
- STRING ASIS
-
- PRINT PUSH
- PRINT OFF
-
- ; Allan and Scott wrote this one day in June, not long before MacHack ’92
- ;
- ;
- ; This version, Allan modified so that it uses a simple install.
- ; This version cannot be uninstalled, and does not allocate and memory.
- ; Note the DetachResource call in the installer.... <grin>
- ; otherwise bad and evil things can happen, when the resource is relesaed!
- ;
- ;
-
- ;Include only the minimum necessary!
-
- INCLUDE 'Traps.a'
- wholeQuick EQU 1
- INCLUDE 'QuickEqu.a'
- wholeSystem EQU 1
- INCLUDE 'SysEqu.a'
- wholeTools EQU 0
- INCLUDE 'ToolEqu.a'
- INCLUDE 'PackMacs.a'
-
-
- PRINT POP
-
- WayBadValue equ $50FF8001 ; An evil value to init to Bus Error
-
- ;----------
-
- SEG 'Essential'
- PROC
- StartOfCode
- _Debugger
- Bsr Essential ; Install Ourselves
- move.L EndOfPatches-StartOfCode,D0
- _SethandleSize ; Remove the install code
- RTS ; And return
- DC.B 'MaChAcK'
-
- Align 2
-
- ;----------
-
-
- ;This block contains the patches.
-
- PatchNewHandle
- Move.l A0,-(sp)
- Lea NewHandleCounter,A0
- Add.l #1,(a0)
- Move.l (SP)+,A0
- Move.l OldNewHandle,-(sp)
- Rts
- OldNewHandle
- DC.L WayBadValue
-
- PatchDisposeHandle
- Move.l A0,-(sp)
- Lea DisposeHandleCounter,A0
- Add.l #1,(a0)
- Move.l (SP)+,A0
- Move.l OldDisposeHandle,-(sp)
- Rts
- OldDisposeHandle
- DC.L WayBadValue
-
-
- PatchNewPtr
- Move.l A0,-(sp)
- Lea NewPtrCounter,A0
- Add.l #1,(a0)
- Move.l (SP)+,A0
- Move.l OldNewPtr,-(sp)
- Rts
- OldNewPtr
- DC.L WayBadValue
-
-
- PatchDisposePtr
- Move.l A0,-(sp)
- Lea DisposePtrCounter,A0
- Add.l #1,(a0)
- Move.l (SP)+,A0
- Move.l OldDisposePtr,-(sp)
- Rts
- OldDisposePtr
- DC.L WayBadValue
-
- PatchRead
- Move.l A0,-(sp)
- Lea ReadCounter,A0
- Add.l #1,(a0)
- Move.W inLoadSeg,D0
- Beq.S @1
- Lea LoadSegHitDisk,A0
- Add.L #1,(A0)
- @1 Move.W inGetResource,D0
- Beq.S @2
- Lea GetResourceHitDisk,A0
- Add.L #1,(A0)
- @2 Move.l (SP)+,A0
- Move.l OldRead,-(sp)
- Rts
- OldRead
- DC.L WayBadValue
-
- PatchWrite
- Move.l A0,-(sp)
- Lea WriteCounter,A0
- Add.l #1,(a0)
- Move.l (SP)+,A0
- Move.l OldWrite,-(sp)
- Rts
- OldWrite
- DC.L WayBadValue
-
- PatchLoadSeg
- Move.l A0,-(sp)
- Lea LoadSegCounter,A0
- Add.l #1,(a0)
- Lea inLoadSeg,A0
- Move.w #1,(A0)
- Move.l (SP)+,A0
- Move.l OldLoadSeg,-(sp)
- Rts
- OldLoadSeg
- DC.L WayBadValue
-
- GetResourceFrame RECORD {Link},Decr
- Result DS.L 1 ; Stack frome for GetResource
- Type DS.L 1
- ID DS.W 1
- Return DS.L 1
- Link DS.L 1
- FrameSZ EQU *-Link
- ENDR
-
- PatchGetResource
- With GetResourceFrame
- Link A6,#FrameSZ
- Move.l A0,-(sp)
- Lea GetResourceCounter,A0
- Add.l #1,(a0)
- Lea inGetResource,A0
- Move.w #1,(A0)
- Move.l (SP)+,A0
-
- Move.L Result(a6),-(sp) ; Move the result value...
- Move.L Type(a6),-(sp) ; and the type
- Move.W ID(a6),-(sp) ; and the ID
-
- Pea MyTailPatch ; The place for us to return to
- Move.l OldGetResource,-(sp)
- Rts ; Do Scott’s Really cool Jump with No registers Blown
-
- MyTailPatch
- Move.L A0,-(SP)
-
- Lea inGetResource,A0
- Clr.W (A0) ; OK, So now we are back, and we can clean up
- Lea inLoadSeg,A0
- Clr.W (A0)
-
- Move.L (SP)+,A0
-
- Move.L (SP)+,Result(a6)
- Unlk A6
- Move.L (SP),6(SP) ; Put the return address up the stack,
- Add #6,SP ; and clean up the stack
- RTS
-
- EndWith
-
- OldGetResource
- DC.L WayBadValue
-
- ; ••••••••••••••••••••••• T H I S I S S C O T T ' S C O D E ••••••••••••••••••••••
-
- redrawInterval equ 60
-
- PatchGNEFilter
-
- MOVEM.L D0-D2/A0-A1,-(SP)
-
- move.l evtTicks(A1),D1 ; tickCount as of now
- move.l GNEFilterTimer,D2 ; tickCount at last update
- sub.l D2,D1 ; ticks since last update
- cmp.l #redrawInterval,D1
- blt.s @Done ; branch if elapsed < redrawInterval
- Lea GNEFilterTimer,A0
- move.l evtTicks(a1),(a0) ; remember the time
-
- Clr.W -(SP)
- _FlashMenuBar
- Lea DebugFlag,A0
- Tst.W (A0)
- Beq.S @Done
- _Debugger
- Bsr.S ClearTheDataBlock
-
- @Done Movem.L (SP)+,D0-D2/A0-A1
- Move.l OldGNEFilter,-(sp)
- Rts
-
- OldGNEFilter
- DC.L WayBadValue
- GNEFilterTimer
- DC.L 0
-
-
- ; This is the routine called by Gestalt to return the Proc Pointer.
- ;
- ; OSErr gestaltSelectorProc(OSType selector,long *response);
- ;
- ; Since this is called from Gestalt, we do not have to save any registers
-
- ReturnTheGestaltHandlerProc
-
- Lea GestaltHandlerProc,A1
- Move.w #0,$0a(Sp) ; No Error ocurred here!
- Move.l 4(SP),A0
- Move.l A1,(A0) ; put the result into the right place....
- Move.L (SP)+,8(Sp) ; Get the return address
- Addq.w #8,A7 ; Lose the args
- Rts ; And return
- Hey, why is this different?
-
-
- ReturnDataBlock
- Lea NewHandleCounter,A1
- Rts
-
- ;
- ; This Function clears the counters, and updates the running totals...
- ;
-
- ClearTheDataBlock
- Lea NewHandleCounter,A0
- move.L (A0),D0
- Add.L D0,4(A0)
- Clr.L (A0)
- Lea DisposeHandleCounter,A0
- move.L (A0),D0
- Add.L D0,4(A0)
- Clr.L (A0)
- Lea NewPtrCounter,A0
- move.L (A0),D0
- Add.L D0,4(A0)
- Clr.L (A0)
- Lea DisposePtrCounter,A0
- move.L (A0),D0
- Add.L D0,4(A0)
- Clr.L (A0)
- Lea ReadCounter ,A0
- move.L (A0),D0
- Add.L D0,4(A0)
- Clr.L (A0)
- Lea WriteCounter,A0
- move.L (A0),D0
- Add.L D0,4(A0)
- Clr.L (A0)
- Lea LoadSegCounter,A0
- move.L (A0),D0
- Add.L D0,4(A0)
- Clr.L (A0)
- Lea LoadSegHitDisk,A0
- move.L (A0),D0
- Add.L D0,4(A0)
- Clr.L (A0)
- Lea GetResourceCounter,A0
- move.L (A0),D0
- Add.L D0,4(A0)
- Clr.L (A0)
- Lea GetResourceHitDisk,A0
- move.L (A0),D0
- Add.L D0,4(A0)
- Clr.L (A0)
- Move.l #0,A1
-
- Rts
-
- UninstallRoutine
- Move.l #0,A1 ; Just return Null
- Rts
-
-
- ; Define a routine actually does the gestalt things....
- ; Has the following interface.
- ;
- ; Defined using Pascal syntax, since we may want to call it from there!
- ;
- ; long GestaltHandlerProc(short selector, char *param);
- ;
-
- sTablePointer equ 0
- sClearTable equ 1
- sUninstall equ 2
-
-
- GestaltHandlerFrame RECORD {Link},Decr
- Result DS.L 1 ; Stack frome for GestaltHandlerProc
- selector DS.W 1
- param DS.L 1
- Return DS.L 1
- Link DS.L 1
- FrameSZ EQU *-Link
- ENDR
-
- GestaltHandlerProc
- With GestaltHandlerFrame
- Link A6,#FrameSZ ; No need for locals here
- Movem.l A0-A2/D0-D2,-(SP) ; save some registers
- Move.W selector(A6),D0
- Move.L param(A6),A1
- Asl.W #2,D0 ; multiply by 4
- Lea myJumpTable,A0
- Move.W (A0,D0.W),D0 ; index to find the right code...
- Jsr (A0,D0.W) ; and do the thing....
- move.l A1,Result(A6) ; and put the result back
- Unlk A6
- Movem.l (SP)+,A0-A2/D0-D2 ; restore the registers
- Move.L (SP),$6(A6) ; Move the return address up....
- Addq #6,SP ; clean up the stack
- Rts
- EndWith
-
- ; Set up our jumptable.
- ; All these values should be negative, since they are before this!
- ;
-
- myJumpTable
-
- DC.W ReturnDataBlock - myJumpTable
- DC.W ClearTheDataBlock - myJumpTable
- DC.W UninstallRoutine - myJumpTable
- DC.W 0
-
- Align 2
-
- PatchPtr DC.L 0
- DebugFlag DC.W 1
- didARead DC.W 0
- inGetResource DC.W 0
- inLoadSeg DC.W 0
-
- ; The table is kept as two longs, The first is the count,
- ; which is reset every time, and the second is a running total, Never reset.
-
- TheDataBlock
-
- NewHandleCounter DC.L 0,0
- DisposeHandleCounter DC.L 0,0
- NewPtrCounter DC.L 0,0
- DisposePtrCounter DC.L 0,0
- ReadCounter DC.L 0,0
- WriteCounter DC.L 0,0
- LoadSegCounter DC.L 0,0
- LoadSegHitDisk DC.L 0,0
- GetResourceCounter DC.L 0,0
- GetResourceHitDisk DC.L 0,0
-
- EndOfTheList DC.L -1,-1,-1,-1 ; just a sentiel value, so we can easily see the list
- ; when debugging! (Which is never needed!)
-
-
- ;----------
- EndOfPatches
-
- ;----------
-
- Credits
- DC.B 'AppleLink addresses: Allan & Scott'
-
- ALIGN 2
- Essential
-
- ;Set up here.
-
- ; Typically, you should mark your INIT resource as Preload & Locked.
- ; This gets it in the "application" heap nice and early and nice and low.
- ; Because we are going to do that, we’re not going to waste code to
- ; do what the resource manager is happy to do for us.
-
- lea StartOfCode,a0
- _RecoverHandle
- _HLock ; just lock me down in case...
- Move.L A0,-(SP)
- _DetachResource ; Since we are going to leave it lying around...
-
- ShiftMask equ 0
-
- ; Do the polite thing, and don’t load if the user doesn’t want us.
- Lea KeyMap,a0
- BTST #ShiftMask,7(a0)
- BNZ BailOut
-
- NewHandle equ $A122
- DisposeHandle equ $A023
- NewPtr equ $A11E
- DisposePtr equ $A01F
- Read equ $A002
- Write equ $A003
- LoadSeg equ $A9F0
- GetResource equ $A9A0
-
- ; jGNEFilter equ 666 ; You decide…
-
- ;Set up the patches-to-be.
-
- LEA OldGNEFilter,A0
- move.l jGNEFilter,(A0) ; save off the old jGNEFilter
-
- MOVE.W #NewHandle,D0
- _GetTrapAddress newOS
- LEA OldNewHandle,A1
- MOVE.L A0,(A1)
-
- MOVE.W #DisposeHandle,D0
- _GetTrapAddress newOS
- LEA OldDisposeHandle,A1
- MOVE.L A0,(A1)
-
- MOVE.W #NewPtr,D0
- _GetTrapAddress newOS
- LEA OldNewPtr,A1
- MOVE.L A0,(A1)
-
- MOVE.W #DisposePtr,D0
- _GetTrapAddress newOS
- LEA OldDisposePtr,A1
- MOVE.L A0,(A1)
-
- MOVE.W #Read,D0
- _GetTrapAddress newOS
- LEA OldRead,A1
- MOVE.L A0,(A1)
-
- MOVE.W #Write,D0
- _GetTrapAddress newOS
- LEA OldWrite,A1
- MOVE.L A0,(A1)
-
- MOVE.W #LoadSeg,D0
- _GetTrapAddress newTool
- LEA OldLoadSeg,A1
- MOVE.L A0,(A1)
-
- MOVE.W #GetResource,D0
- _GetTrapAddress newTool
- LEA OldGetResource,A1
- MOVE.L A0,(A1)
-
-
- InstallPatches
-
- move.l PatchPtr,a1
-
- LEA PatchGNEFilter,A0 ; somebody’s got to get the utility check!
- Move.L A0,jGNEFilter ; to get some time, patch us into jGNEFilter (GetNextEvent)
-
- Lea PatchNewHandle,A0
- MOVE.W #NewHandle,D0
- _SetTrapAddress newOS
-
- Lea PatchDisposeHandle,A0
- MOVE.W #DisposeHandle,D0
- _SetTrapAddress newOS
-
- Lea PatchNewPtr,A0
- MOVE.W #NewPtr,D0
- _SetTrapAddress newOS
-
- Lea PatchDisposePtr,A0
- MOVE.W #DisposePtr,D0
- _SetTrapAddress newOS
-
- Lea PatchRead,A0
- MOVE.W #Read,D0
- _SetTrapAddress newOS
-
- Lea PatchWrite,A0
- MOVE.W #Write,D0
- _SetTrapAddress newOS
-
- Lea PatchLoadSeg,A0
- MOVE.W #LoadSeg,D0
- _SetTrapAddress newTool
-
- Lea PatchGetResource,A0
- MOVE.W #GetResource,D0
- _SetTrapAddress newTool
-
- lea ReturnTheGestaltHandlerProc,A0
- Move.L #'Sntl',D0
- _NewGestalt ; If it fails, then something bad happened...
- ; but nothing we can do about it now
-
-
- bra.s loaded
-
- ;Common exit-point.
- BailOut
- ;
- ; PROCEDURE ShowINIT(iconID: Integer; moveX: Integer);
- IMPORT SHOWINIT:CODE
-
- didntLoadIconID equ -4063
- patchLoadedIconID equ -4064
-
- move.w #didntLoadIconID,-(a7) ; Shift held -- Didn’t load
- bra.s ShowIt
-
-
- loaded move.w #patchLoadedIconID,-(a7) ; OK Show the ICON and go
- ShowIt move.w #-1,-(a7)
- Bsr SHOWINIT
-
- exit RTS
-
- ; What happens to this locked block, you ask? Easy, the heap is about to
- ; get blown away, so we really don’t have to do anything to tidy up.
-
- END
-
-
- ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- AOptions = -case on
-
-
- Essential ƒ Essential.rsrc Essential.a.o
- Duplicate -y Essential.rsrc {Targ}
- Link -o {Targ} -rt INIT=-4064 -sg Essential -ra =resLocked ∂
- Essential.a.o ∂
- {libraries}ShowInit.a.o
- SetFile -t INIT -c 'APF2' {Targ}
-
- Essential.rsrc ƒ Essential.r
- Rez -o {Targ} Essential.r
-
-
-